package com.demo;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DbUtil {
    public static Connection getConnection()  {
        String driver = ResourceUtil.getValue("mysql.driver");
        String url = ResourceUtil.getValue("mysql.url");
        String username = ResourceUtil.getValue("mysql.username");
        String password = ResourceUtil.getValue("mysql.password");

        //加载mysql驱动
        try {
            Class.forName(driver);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        //获取数据库连接
        Connection connection = null;
        try {
            connection = DriverManager.getConnection(url,username,password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return connection;
    }
}
